package com.yangming.springboot.deepin.playTest;

import org.junit.Test;

import java.util.concurrent.locks.Lock;

/**
 * @创建人 ym
 * @创建时间 2021/4/12 0012
 * @描述
 **/
public class TwinsLockTest {

    @Test
    public void test(){
        final Lock lock = new TwinsLock();
        class Worker extends Thread{
            @Override
            public void run(){
                while(true){
                    lock.lock();
                    try{
                        SleepUtils.second(1);
                        System.out.println(Thread.currentThread().getName());
                        SleepUtils.second(1);
                    }finally{
                        lock.unlock();
                    }
                }
            }
        }
        for (int i=0;i<10;i++){
            Worker w = new Worker();
            w.setDaemon(true);
            w.start();
        }
        for (int i=0;i<10;i++){
            SleepUtils.second(1);
            System.out.println();
        }
    }

}
